# """
# Name: 'BFM Unit generator'
# Blender: 236
# Group: 'Export'
# Tooltip: 'Select 5 cameras and run this script'
# Author: 'Phantom'
# """

def addzeros(i):
        r=i
        for c in range(len(i),4):
                r="0" + r
        return r

import sys
import Blender
import PIL
from PIL import Image

savefilename = Blender.Draw.PupStrInput("Save to: ", "[write path]")

scene = Blender.Scene.GetCurrent()
context = scene.getRenderingContext()
start = context.startFrame()
end = context.endFrame()
sizex = context.imageSizeX()
sizey = context.imageSizeY()
cameras=0
for c in Blender.Object.GetSelected():
        if(c.getType() == "Camera"):
                cameras+=1
if(cameras==0):
        Blender.Draw.PupMenu("Select a camera first!")
else:
        bigimage = Image.new("RGBA", [cameras*sizex, (end-start+1)*sizey])
        count = 0
        for c in Blender.Object.GetSelected():
                if(c.getType() == "Camera"):
                        scene.setCurrentCamera(c)
                        Blender.Redraw()
                        context.renderAnim()
                        for i in range(start, end+1):
                                smallimage = Image.open(context.getRenderPath() + addzeros(str(i)) + ".jpg")
                                bigimage.paste(smallimage,(count*sizex, (i-start)*sizey))
                        count+=1
        bigimage.save(savefilename)